package org.hiro.velocity;

import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.log.Log4JLogChute;

public class VelocityFactory {

    private static VelocityEngine engine;

    private VelocityFactory() {
    }

    private static VelocityEngine newVelocityEngine() throws Exception {
        VelocityEngine velocity = new VelocityEngine();
        velocity.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, Log4JLogChute.class.getName());
        velocity.setProperty(Log4JLogChute.RUNTIME_LOG_LOG4J_LOGGER, "BuilderPlugin");
        velocity.init();
        return velocity;
    }

    public static VelocityEngine getVelocityEngine() throws Exception {
        if (engine == null) {
            engine = newVelocityEngine();
        }
        return engine;
    }
}